parameters:
  alwaysRun: false
  isExtraPlatformsBuild: false
  isWasmOnlyBuild: false
  browser: 'chrome'
  shouldContinueOnError: false
  runOnlyOnWasmOnlyPipelines: false
  extraBuildArgs: ''
  nameSuffix: ''
  platforms: []

jobs:

# Wasm debugger tests - windows
- template: /eng/pipelines/common/platform-matrix.yml
  parameters:
    jobTemplate: /eng/pipelines/common/global-build-job.yml
    helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
    buildConfig: Release
    runtimeFlavor: mono
    platforms: ${{ parameters.platforms }}
    shouldContinueOnError: ${{ parameters.shouldContinueOnError }}
    variables:
      # map dependencies variables to local variables
      - name: alwaysRunVar
        value: ${{ parameters.alwaysRun }}
      - name: shouldRunOnDefaultPipelines
        value: $[
          or(
            eq(variables['wasmDarcDependenciesChanged'], true),
            eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_tools_illink.containsChange'], true),
            eq(stageDependencies.EvaluatePaths.evaluate_paths_outputs['DarcDependenciesChanged.Microsoft_DotNet_HotReload_Utils_Generator_BuildTool'], true),
            eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_wasmdebuggertests.containsChange'], true))
          ]
    jobParameters:
      testGroup: innerloop
      isExtraPlatforms: ${{ parameters.isExtraPlatformsBuild }}
      ${{ if eq(parameters.nameSuffix, '') }}:
        nameSuffix: Mono_DebuggerTests_${{ parameters.browser }}
      ${{ else }}:
        nameSuffix: ${{ parameters.nameSuffix }}
      buildArgs: -s mono+libs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true /p:TestWasmDebuggerTests=true /p:TestAssemblies=false /p:BrowserHost=$(_hostedOs) /p:DebuggerHost=${{ parameters.browser }} ${{ parameters.extraBuildArgs }}
      timeoutInMinutes: 180
      # if !alwaysRun, then:
      #   if this is runtime-wasm (isWasmOnlyBuild):
      #     - then run only if it would not have run on default pipelines (based
      #       on path changes)
      #     - else run based on path changes
      condition: >-
        or(
          eq(variables['alwaysRunVar'], true),
          and(
            eq(variables['isDefaultPipeline'], variables['shouldRunOnDefaultPipelines']),
            eq(${{ parameters.isWasmOnlyBuild }}, ${{ parameters.runOnlyOnWasmOnlyPipelines }})))
      postBuildSteps:
        - template: /eng/pipelines/libraries/helix.yml
          parameters:
            creator: dotnet-bot
            testRunNamePrefixSuffix: Mono_${{ parameters.browser }}_$(_BuildConfig)
            extraHelixArguments: /p:BrowserHost=$(_hostedOs) /p:_DebuggerHosts=${{ parameters.browser }}
            scenarios:
            - wasmdebuggertests
